package com.fafu.test;

import com.fafu.dao.UserDao;
import com.fafu.domian.user.User;
import com.fafu.tool.HttpClientUtil;
import com.fafu.tool.JsonUtils;
import com.fafu.tool.TokenUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

public class Httpdemo {

	public boolean identityCheck(String idCard, String realName){
		String url = null;
			String result = HttpClientUtil.doGet(url);
		return  false;
	}
	@Test
	public void test() throws Exception {
		String url = "http://localhost:8080/User_war/user/findAll";
		String result = HttpClientUtil.doPost(url);
		System.out.println(result);
		ObjectMapper mapper =new ObjectMapper();
		List <User>list  = mapper.readValue(result,ArrayList.class);
		System.out.println(list.get(1));
		User u =mapper.readValue(mapper.writeValueAsString(list.get(1)) ,User.class);
		System.out.println(u.getUsername());
		List list1 =JsonUtils.parse(result,ArrayList.class);
		System.out.println(list1.get(1).toString());
		String a =list1.get(1).toString()+"你好";
		System.out.println(a);




	}
	@Test
	public void  test1() throws Exception {
		User user = new User();
		user.setUsername("小白");
		user.setPassword("123");

		ObjectMapper mapper =new ObjectMapper();
		String json = mapper.writeValueAsString(user);
		System.out.println(json);
		User u = mapper.readValue(json,User.class);
		System.out.println(u.getUsername());;
		System.out.println(u);

	}
	@Test
	public void test3(){

		System.out.println(TokenUtil.getToken("5464646"));
	}
	@Test
	public void test4(){
		String url = "http://139.224.192.113:8080/verifyToken?token=";
		String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhc2FzZCIsImV4cCI6MTU3ODM5NDMwM30.ClQ92pBzkx3ihgrbXGetFLXsScFAr_NuKUTxZRXb3Vg";
		String api =url+token;
		System.out.println(HttpClientUtil.doPost(api,token));
	}
	@Test
	public void test6(){
		String token = "eJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI1NDY0NjQ2IiwiZXhwIjoxNTc4Mzk2OTY2fQ.PbvGtu5BYWLkL22nLA5aSsUW7OcFOpA-qtsO1RaiHKY";
		System.out.println(TokenUtil.checkToken(token));

	}
	@Test
	public void test7(){
		UserDao userDao= null;
		User u = null;
		try {
			System.out.println(userDao.findByUsername("1125030435@qq.com"));
		}
		catch (Exception e){
			System.out.println(e.getMessage());
		}
	}
	@Test
	public void test333(){
		Map map = TokenUtil.checkToken("");
		System.out.println(map.get("flag"));
	}
	


}
